import axiosReq from '@/utils/axios-req'
import { useProjectInfoStore } from '@/store/projectInfo'
const BASE_URL = import.meta.env.VITE_APP_BASE_URL_SYH
/**
 * 项目评审项信息-列表 -固定id
 * @param data 
 * {
  "id": 1
   }
 * @returns 
 */
export const projectBandInfo = () => {
  const projectId = useProjectInfoStore().projectInfo.id
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectBandInfo/list`,
    method: 'POST',
    data: {
      projectId
    }
  })
}

/**
 * 项目信息-更新锁定状态
 * @param data
 * {
  "lockStatus": 1,
  "id": 1
  }
 * @returns
 */
export const updateLockStatus = (data: any) => {
  const projectId = useProjectInfoStore().projectInfo.id
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectInfo/updateLockStatus`,
    method: 'POST',
    data: {
      id: projectId,
      ...data
    },
    showMsg: true
  })
}

/**
 * 项目评审项-保存
 * @param data 
 * {
  "projectId": 1,
  "itemList": []
}
 * @returns 
 */
export const projectBandInfoSave = (itemList: any) => {
  const projectId = useProjectInfoStore().projectInfo.id
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectBandInfo/save`,
    method: 'POST',
    data: {
      projectId,
      itemList
    },
    showMsg: true
  })
}

/**
 * 绑定模板/项目评审项
 * @param itemList 
 * {
  "projectId": 10,
  "type": "template",
  "targetId": 2
}
 * @returns 
 */
export const bandTemplateOrProjectItem = (data: any) => {
  const projectId = useProjectInfoStore().projectInfo.id
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectBandInfo/bandTemplateOrProjectItem`,
    method: 'POST',
    data: {
      projectId,
      ...data
    },
    showMsg: true
  })
}

/**
 * 评审项信息-删除
 * @param data
 *  [1,2,3]
 */
export const projectBandInfoDelete = (data: any) => {
  const projectId = useProjectInfoStore().projectInfo.id
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectItemInfo/remove`,
    method: 'POST',
    data: {
      projectId,
      ids: data
    },
    showMsg: true
  })
}

/**
 * 评审项信息-查看
 * @param params id=50
 * @returns
 */
export const projectItemInfoView = (params: any) => {
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectItemInfo/view`,
    method: 'GET',
    params
  })
}

/**
 * 评分点信息-查看树
 * @param params itemId=1
 * @returns
 */
export const projectPointInfoView = (params: any) => {
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectPointInfo/view`,
    method: 'GET',
    params
  })
}

/**
 * 评分点信息-树维护
 * @param data
 * {
  "projectId": 1,
  "itemId": 1,
  "addList": []
  "updateList": []
  "deleteList": []
}
 * @returns
 */
export const projectPointInfoSaveTree = (data: any) => {
  const projectId = useProjectInfoStore().projectInfo.id
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectPointInfo/saveUpdate`,
    method: 'POST',
    data: {
      projectId,
      ...data
    },
    showMsg: true
  })
}

/**
 * 评分点信息-保存
 * @param data
 * {
  "id": 1,
  "itemId": 1,
  "name": "评分点名称",
  "description": "评分点描述",
  "scoreCollectWay": "scoreCollectWay",
  "markMode": "markMode",
  "flowOrderCode": "flowOrderCode",
  "orderNo": 1
}
 * @returns
 */
export const projectPointInfoSave = (data: any) => {
  const projectId = useProjectInfoStore().projectInfo.id
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectItemInfo/saveUpdate`,
    method: 'POST',
    data: {
      projectId,
      ...data
    },
    showMsg: true
  })
}

/**
 * 项目评审项信息-列表-通过项目ID获取
 * @param data ?projectId=6
 * @returns
 */
export const getListByProjectId = () => {
  const projectId = useProjectInfoStore().projectInfo.id
  return axiosReq({
    baseURL: BASE_URL,
    url: `/cloud/pbgl/projectBandInfo/listByProjectId`,
    method: 'get',
    params: {
      projectId
    }
  })
}
